#!/bin/bash

SCRIPT_DIR=$(cd `dirname $0` && pwd)
cd "${SCRIPT_DIR}"

source config.libffi

rm -rf ./_install

if [ ! -f "${ARCHIVE}" ]; then
    wget "https://github.com/libffi/libffi/releases/download/v${VERSION}/${ARCHIVE}"
fi

tar zxvf "${ARCHIVE}"

cd "${PACKAGE}" || exit 1

# See https://github.com/libffi/libffi/issues/552.
sed -i 's/mv \$srcdir\/config.log/cp \$srcdir\/config.log/' configure

./configure --host=arm-openwrt-linux --prefix="$(pwd)/build"
